package com.sl.plugin.step.selenium.screenshot;

import com.sl.core.engine.meta.impl.AbstractProcessCompDescriptor;
import com.sl.core.engine.step.ProcessCompService;
import com.sl.core.engine.step.impl.AbstractProcessComp;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;


/**
 */
public class SeleniumScreenshotComp extends AbstractProcessComp<WebDriver, WebDriver> implements ProcessCompService {


    public SeleniumScreenshotComp(AbstractProcessCompDescriptor abstractProcessCompDescriptor) {
        super(abstractProcessCompDescriptor);
    }


    @Override
    public WebDriver input(WebDriver driver) {
        String key = meta.getStrAttr("key");
        TakesScreenshot takesScreenshot = (TakesScreenshot) driver;
        // 全屏截图 也可以按照元素截图 element.getScreenshotAs
        String screenshotAs = takesScreenshot.getScreenshotAs(OutputType.BASE64);

        setVariable(key, screenshotAs);

        return driver;
    }


}
